//
//  MyCompetionUPProducetCell.m
//  ShangHaiTuJI
//
//  Created by xiaoxiangtuji on 2017/11/3.
//  Copyright © 2017年 xiaoxiangtuji. All rights reserved.
//

#import "MyCompetionUPProducetCell.h"
#import "RecordListModel.h"
@implementation MyCompetionUPProducetCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
-(void)setModel:(RecordListModel *)model{
    _model = model;
    UILabel *successLabel = [[UILabel alloc] init];
    successLabel.text = @"上传成功";
    successLabel.textColor = COLOR_HEX(0xFFC91F);
    successLabel.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:successLabel];
    [successLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.mas_right).offset(scaleLeftAndRight(-10));
        make.top.equalTo(self.contentView.mas_top).offset(scaleTopAndBottom(12.5));
        make.width.mas_equalTo(scaleLeftAndRight(70));
        make.height.mas_equalTo(scaleTopAndBottom(15));
    }];
    UILabel *competionLebel = [[UILabel alloc] init];
    competionLebel.text = _model.matchName;
    competionLebel.textColor = COLOR_HEX(0x121212);
    competionLebel.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:competionLebel];
    [competionLebel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(scaleLeftAndRight(10));
        make.top.equalTo(self.contentView.mas_top).offset(scaleTopAndBottom(12.5));
        make.height.mas_equalTo(scaleTopAndBottom(15));
        make.right.equalTo(successLabel.mas_left).offset(scaleLeftAndRight(-10));
    }];
    UIView *topLineView = [[UIView alloc] init];
    topLineView.backgroundColor = COLOR_HEX(0xE8E8E8);
    [self.contentView addSubview:topLineView];
    [topLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(successLabel.mas_bottom).offset(scaleTopAndBottom(12.5));
        make.height.mas_equalTo(0.5);
        make.width.mas_equalTo(WIDTH);
        make.left.equalTo(self.contentView.mas_left);
    }];
    UIImageView *productImageView = [[UIImageView alloc] init];
    [productImageView sd_setImageWithURL:[NSURL URLWithString:_model.filePath] placeholderImage:[UIImage imageNamed:@""]];
    [self.contentView addSubview:productImageView];
    [productImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(scaleLeftAndRight(10));
        make.top.equalTo(topLineView.mas_bottom).offset(scaleTopAndBottom(7));
        make.size.mas_equalTo(CGSizeMake(scaleLeftAndRight(129), scaleTopAndBottom(82)));
    }];
    UILabel *productLabel = [[UILabel alloc] init];
    productLabel.text = _model.name;
    productLabel.textColor = COLOR_HEX(0x121212);
    productLabel.font = [UIFont fontWithName:@"PingFangSC-Medium" size:15];
    if (WIDTH > 375.f) {
        productLabel.font = [UIFont fontWithName:@"PingFangSC-Medium" size:23];
    }
    if (WIDTH < 375.f) {
        productLabel.font = [UIFont fontWithName:@"PingFangSC-Medium" size:10];
    }
    [self.contentView addSubview:productLabel];
    [productLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(productImageView.mas_right).offset(scaleLeftAndRight(10));
        make.height.mas_equalTo(scaleTopAndBottom(15));
        make.right.equalTo(self.contentView.mas_right).offset(scaleLeftAndRight(-10));
        make.top.equalTo(topLineView.mas_bottom).offset(scaleTopAndBottom(30));
    }];
    UILabel *autorLabel = [[UILabel alloc] init];
    autorLabel.text = [NSString stringWithFormat:@"作者:%@",_model.babyName];
    autorLabel.textColor = COLOR_HEX(0xABABAB);
    autorLabel.font = [UIFont systemFontOfSize:12];
    
    [self.contentView addSubview:autorLabel];
    [autorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(productImageView.mas_right).offset(scaleLeftAndRight(10)); make.top.equalTo(productLabel.mas_bottom).offset(scaleTopAndBottom(8));
        make.height.mas_equalTo(scaleTopAndBottom(12));
        make.right.equalTo(self.contentView.mas_right).offset(scaleLeftAndRight(-10));
    }];
    UIView *bottomLineView = [[UIView alloc] init];
    bottomLineView.backgroundColor = COLOR_HEX(0xE8E8E8);
    [self.contentView addSubview:bottomLineView];
    [bottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(productImageView.mas_bottom).offset(scaleTopAndBottom(7));
        make.height.mas_equalTo(0.5);
        make.width.mas_equalTo(WIDTH);
        make.left.equalTo(self.contentView.mas_left);
    }];
    UIButton *shareBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    shareBtn.titleLabel.font = [UIFont systemFontOfSize:13];
    shareBtn.tag = 100000 + [model.matchId integerValue];
    [shareBtn addTarget:self action:@selector(shareQQAndWechat:) forControlEvents:UIControlEventTouchUpInside];
    [shareBtn setTitle:@"分享赛事" forState:UIControlStateNormal];
    [shareBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    shareBtn.backgroundColor = COLOR_HEX(0xFF5428);
    [self.contentView addSubview:shareBtn];
    [shareBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.mas_right).offset(scaleLeftAndRight(-15));
        make.top.equalTo(bottomLineView.mas_bottom).offset(scaleTopAndBottom(12));
        make.bottom.equalTo(self.contentView.mas_bottom).offset(scaleTopAndBottom(-12));
        make.width.mas_equalTo(scaleLeftAndRight(70));
    }];
    
    UIButton *lookBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    lookBtn.tag = 100001 + [model.matchId integerValue];
    NSLog(@"这是tag%ld",lookBtn.tag);
    lookBtn.titleLabel.font = [UIFont systemFontOfSize:13];
    [lookBtn setTitle:@"查看作品" forState:UIControlStateNormal];
    [lookBtn setTitleColor:COLOR_HEX(0x121212) forState:UIControlStateNormal];
    [lookBtn addTarget:self action:@selector(lookProduce:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:lookBtn];
    [lookBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(shareBtn.mas_left).offset(scaleLeftAndRight(-17));
        make.top.equalTo(bottomLineView.mas_bottom).offset(scaleTopAndBottom(12));
        make.bottom.equalTo(self.contentView.mas_bottom).offset(scaleTopAndBottom(-12));
        make.width.mas_equalTo(scaleLeftAndRight(70));
    }];
    lookBtn.layer.borderColor = COLOR_HEX(0x121212).CGColor;
    lookBtn.layer.borderWidth = 1;
    UIImageView *overImageV = [[UIImageView alloc] init];
    overImageV.image = [UIImage imageNamed:@"矢量智能对象拷贝3"];
    [self.contentView addSubview:overImageV];
    [overImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(shareBtn.mas_centerY);
        make.left.equalTo(self.contentView.mas_left).offset(scaleLeftAndRight(15));
        make.size.mas_equalTo(CGSizeMake(scaleLeftAndRight(12), scaleTopAndBottom(12)));
        
    }];
    UILabel *timeLabel = [[UILabel alloc] init];
    timeLabel.text = [self getHour:@"" systemTime:_model.matchSubmittime];
    timeLabel.font = [UIFont systemFontOfSize:12];
    timeLabel.textColor = COLOR_HEX(0xB3B3B3);
    [self.contentView addSubview:timeLabel];
    [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(shareBtn.mas_centerY);
        make.left.equalTo(overImageV.mas_right).offset(scaleLeftAndRight(7));
        make.right.equalTo(lookBtn.mas_left).offset(scaleLeftAndRight(10));
        make.height.mas_equalTo(scaleTopAndBottom(12));
        
    }];
}

/**
 根据时间戳获取到时间差
 
 */
- (NSString* )getHour:(NSString *)takeCarTime systemTime:(NSString *)systemTime

{
    
    //  时区相差8个小时 加上这个时区即是北京时间
    
    NSTimeZone *timeZone = [NSTimeZone systemTimeZone];
    
    NSInteger delta = [timeZone secondsFromGMT];
    
    NSDate *DRstartDate = [NSDate date];
    NSDate *DRendDate = [[NSDate alloc] initWithTimeIntervalSince1970:[systemTime doubleValue]/1000 + delta];
    NSLog(@"开始时间%@",DRstartDate);
    NSLog(@"结束时间%@",DRendDate);
    // 日历对象 （方便比较两个日期之间的差距）
    
    NSTimeInterval interTime = [DRendDate timeIntervalSinceNow];
    //计算天数、时、分、秒
    
    int days = ((int)interTime)/(3600*24);
    
    int hours = ((int)interTime)%(3600*24)/3600;
    
    int minutes = ((int)interTime)%(3600*24)%3600/60;
    
    NSString *dateContent = [[NSString alloc] initWithFormat:@"倒计时:%i天%i时%i分",days,hours,minutes];
    NSLog(@"嘎嘎嘎嘎%@",dateContent);
    return dateContent;
    
}

-(void)lookProduce:(UIButton *)btn{
    NSLog(@"%ld",btn.tag);
    NSString *matchId = [NSString stringWithFormat:@"%ld",btn.tag - 100001];
    self.produceBlock(matchId);
}
-(void)shareQQAndWechat:(UIButton *)btn{
        NSString *matchId = [NSString stringWithFormat:@"%ld",btn.tag - 100000];
    self.shareQQAndWechatBlock(matchId);
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
